﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using System.Xml;
using CNVP.Framework;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class PowerManage : AdminPage
    {
        public int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 87)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Public.IsNumber(Request.QueryString["ID"]))
            {
                id = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (!IsPostBack)
            {
                string _RoleName = "";
                var model_AdminRole=new BLL.CNVP_AdminRole().GetSingle_CNVP_AdminRoleById(id);
                if (model_AdminRole != null)
                {
                    _RoleName = model_AdminRole.RoleName;
                }
                lbTitle.Text = " > " + _RoleName;
                uid.Text = id.ToString();
                getPower();
            }
            
        }
        /// <summary>
        /// 读取权限
        /// </summary>
        private void getPower()
        {
            new BLL.BLLMenu().BuildAllPowerlabel(lblTong, id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void tijiao_Click(object sender, EventArgs e)
        {
            try
            {
                string[] cbMenu = Request.Form["cbMenu"].Split(Convert.ToChar(","));
                new BLL.CNVP_AdminRoleMenu().Delete_CNVP_AdminRoleMenu(id);
                for (int i = 0; i < cbMenu.Length; i++)//注意从‘1’开始
                {
                    int cnMenuValue = int.Parse(cbMenu[i].ToString());
                    var rows = new BLL.CNVP_AdminRoleMenu().Add_CNVP_AdminRoleMenu(new Model.CNVP_AdminRoleMenu()
                    {
                        MenuID = cnMenuValue,
                        AdminRoleID = id
                    });
                }
                BasePage.MessageBox("设置成功！", "AdminRoleList.aspx");
                lblTong.Text = "";//首先清除
                getPower();
            }
            catch
            {
                MessageUtils.ShowPre("悲剧，出错了！");
            }
        }
    }
}